<?php
/*!
Application_Model_Building 
REQUIRES db.php

*/

require("db.php");

class Application_Model_Building {
	
	public function get_all_buildings()
	{
		//! Returns associative array of all buildings.\n
		
		$qstring = "SELECT building_name FROM building ORDER BY building_name";
		$result = mysql_query($qstring);
		$compiledNames = array();
		while($building = mysql_fetch_assoc($result)){
			array_push($compiledNames,$building["building_name"]);
		}
		return $compiledNames;
	}
	
	public function search_by_building($building) 
	{
		//! Queries $building.\n
		//! Returns associative array LIKE $building.\n
		
        $qstring = "SELECT c.component_id, c.ip_address, c.serial_number, d.device_name, c.last_inspected, b.building_name, c.location, c.component_comments FROM component c, device d, make m, building b WHERE b.building_name = \"" . $building . "\" AND c.device_id = d.device_id AND c.building_id = b.building_id ORDER BY c.location";
		$result = mysql_query($qstring);
		$compiledResults=array();
		while($row=mysql_fetch_assoc($result)){
			array_push($compiledResults,$row);
		}
		
		return $compiledResults;
	}
}
